package sktit.practice.jpaint.gui;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;

import sktit.practice.jpaint.draw.Draw;
import sktit.practice.jpaint.draw.PolygonDraw;

public class JPaintApplicationWindow extends ApplicationWindow {
	
	private Draw draw;
	
	public JPaintApplicationWindow() 
	{
		super(null);
		addStatusLine();
		addMenuBar();

//		addToolBar(SWT.FLAT | SWT.WRAP);
	}
	
	protected MenuManager createMenuManager()
	{
		MenuManager main_menu = new MenuManager(null);
		
		MenuManager file_menu = new MenuManager("&File");
		
		file_menu.add(new Action("&New", 
				ImageDescriptor.createFromFile(null, "images/new.gif")){
			
			public void run()
			{
				draw.getCanvasManager().clear();
				getShell().redraw();
			}
		});
		
		file_menu.add(new Action("&Open", 
				ImageDescriptor.createFromFile(null, "images/open.gif")){
			
			public void run()
			{
				FileDialog dlg = new FileDialog(getShell(), SWT.OPEN);
				dlg.setFilterExtensions(new String[]{"*.jpt", "*.*"});
				dlg.setFilterNames(new String[]{"JPaint (*.jpt)", "All files(*.*)"});
				dlg.open();
			}
		});
		
		file_menu.add(new Action("&Save", 
				ImageDescriptor.createFromFile(null, "images/save.png")){
			
			public void run()
			{
				FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
				dlg.setFilterExtensions(new String[]{"*.jpt", "*.*"});
				dlg.setFilterNames(new String[]{"JPaint (*.jpt)", "All files(*.*)"});
				dlg.open();
			}
		});
		
		file_menu.add(new Action("&Exit", 
				ImageDescriptor.createFromFile(null, "images/new.gif")){
			
			public void run()
			{
				System.out.println("new");
			}
		});
		
		main_menu.add(file_menu);
		
		MenuManager edit_menu = new MenuManager("&Edit");
		edit_menu.add(new Action("&Edit", 
				ImageDescriptor.createFromFile(null, "images/new.gif")){
			
			public void run()
			{
				System.out.println("new");
			}
		});
		main_menu.add(edit_menu);
		
		MenuManager help_menu = new MenuManager("&Help");
		help_menu.add(new Action("&Help", 
				ImageDescriptor.createFromFile(null, "images/new.gif")){
			
			public void run()
			{
				System.out.println("new");
			}
		});
		main_menu.add(help_menu);
		
		return main_menu;
	}

	protected Control createContents(Composite parent)
	{
		Display display = Display.getCurrent();
		Shell shell = getShell();
		
		shell.setText("JPaint");
		shell.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
		
		
		draw = new PolygonDraw(shell, display, display.getSystemColor(SWT.COLOR_BLACK), 1, SWT.LINE_DASHDOT);
		
		return parent;
	}
	
	public static void main(String[] args)
	{
		JPaintApplicationWindow window = new JPaintApplicationWindow();
		window.setBlockOnOpen(true);
		window.open();
		Display.getCurrent().dispose();
	}
	
}
